// src/router/index.js
import { createRouter, createWebHistory } from 'vue-router';
import Home from '@/views/Home.vue';
import ModuleManagement from '@/views/ModuleManagement.vue';
import InterfaceManagement from '@/views/InterfaceManagement.vue';
import CreateInterface from '@/views/CreateInterface.vue';
import ProjectManagementView from '@/views/ProjectManagementView.vue';
import ProjectList from '@/views/ProjectList.vue';
import ProjectDetails from '@/views/ProjectDetails.vue';
import ContainerView from '@/views/container/ContainerView.vue'; 
import CreateProject from '@/views/CreateProject.vue';
import Login from '@/views/Login.vue'; 
import NotFound from '@/views/NotFound.vue'; // 添加 404 页面

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
    meta: { showNavbar: true }, // 显示导航栏
  },
  {
    path: '/',
    name: 'ContainerView',
    component: ContainerView,
    children: [
      {
        path: 'project-management',
        name: 'ProjectManagement',
        component: ProjectManagementView,
        meta: { showNavbar: true }, // 显示导航栏
        children: [
          {
            path: 'list',
            name: 'ProjectList',
            component: ProjectList,
            meta: { showChildren: true } // 添加 meta 字段
          },
          {
            path: 'create',
            name: 'CreateProject',
            component: CreateProject,
            meta: { showChildren: true } // 添加 meta 字段
          },
          {
            path: 'details/:id',
            name: 'ProjectDetails',
            component: ProjectDetails,
            meta: { showChildren: true } // 添加 meta 字段
          }
        ]
      },
      {
        path: 'module-management',
        name: 'ModuleManagement',
        component: ModuleManagement,
        meta: { showNavbar: true }, // 显示导航栏
      },
      {
        path: 'interface-management',
        name: 'InterfaceManagement',
        component: InterfaceManagement,
        meta: { showNavbar: true }, // 显示导航栏
      },
      {
        path: 'create-interface',
        name: 'CreateInterface',
        component: CreateInterface,
        meta: { showNavbar: true }, // 显示导航栏
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { showNavbar: false } // 不显示导航栏
  },
  {
    path: '/:pathMatch(.*)*', // 通配符路径
    name: 'NotFound',
    component: NotFound
  }
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes
});

router.beforeEach((to, from, next) => {
  console.log('Navigating to:', to);
  next();
});

export default router;